package edu.towson.cis.cosc442.project4.coffeemaker;

import junit.framework.TestCase;

/**
 *
 */
public class CoffeeMakerTest extends TestCase {
	private CoffeeMaker cm;
	private Inventory i;
	private Recipe r1;

	public void setUp() {
		cm = new CoffeeMaker();
		i = cm.checkInventory();

		r1 = new Recipe();
		r1.setName("Coffee");
		r1.setPrice(50);
		r1.setAmtCoffee(6);
		r1.setAmtMilk(1);
		r1.setAmtSugar(1);
		r1.setAmtChocolate(1);
		
		
		
	}

	//Tests to see if the recipe is successfully added	
	public void testAddRecipe1() {
		assertTrue(cm.addRecipe(r1));
	}
	//Tests to see if it returns false when you add a recipe that already exists
	public void testAddRecipe2(){
		cm.addRecipe(r1);
		assertFalse(cm.addRecipe(r1));
	}
	
	//Tests to see if it returns false when you add a recipe once the 
	//array of recipes is already full
	public void testAddRecipe3(){		
		Recipe r2 = new Recipe();
		r2.setName("two");
		Recipe r3 = new Recipe();
		r3.setName("three");
		Recipe r4 = new Recipe();
		r4.setName("four");
		cm.addRecipe(r1);
		cm.addRecipe(r2);
		cm.addRecipe(r3);
		cm.addRecipe(r4);
		assertFalse(cm.addRecipe(new Recipe()));
	}
	
	//Adds a recipe and deletes it, checks to see if successful
	public void testDeleteRecipe1() {
		cm.addRecipe(r1);
		assertTrue(cm.deleteRecipe(r1));
	}
	
	//Removes a null recipe
	public void testDeleteRecipe2(){
		assertFalse(cm.deleteRecipe(null));
		
	}
	
	//Removes a null recipe
		public void testDeleteRecipe3(){
			assertFalse(cm.deleteRecipe(r1));			
		}

	//Adds a recipe, edits it and checks to see if successful
	public void testEditRecipe1() {
		cm.addRecipe(r1);
		Recipe newRecipe = new Recipe();
		newRecipe = r1;
		newRecipe.setAmtSugar(2);
		assertTrue(cm.editRecipe(r1, newRecipe));
	}
	
	//Adds a recipe, edits it and checks to see if successful
	public void testEditRecipe2() {
		Recipe newRecipe = new Recipe();
		newRecipe = r1;
		newRecipe.setAmtSugar(2);
		assertFalse(cm.editRecipe(r1, newRecipe));
	}
	
	//Checks to see if adding something to the inventory is successful
	public void testAddInventory1(){
		cm.addInventory(50, 50, 50, 50);
		assertEquals(i.getChocolate(), 65, .05);
		assertEquals(i.getCoffee(), 65, .05);
		assertEquals(i.getMilk(), 65, .05);
		assertEquals(i.getSugar(), 65, .05);
	}
	
	//Checks to see if adding something with a negative value is unsuccessful
	public void testAddInventory2(){
		assertFalse(cm.addInventory(0, -1,0,0));
	}
	
	//Checks to see if adding something with a negative value is unsuccessful
	public void testAddInventory3(){
		assertFalse(cm.addInventory(0, 0,-1,0));
	}
	
	//Checks to see if adding something with a negative value is unsuccessful
	public void testAddInventory4(){
		assertFalse(cm.addInventory(0, 0,0,-1));
	}

	//Checks to see if adding something with a negative value is unsuccessful
	public void testAddInventory5(){
		assertFalse(cm.addInventory(-1, 0,0,0));
	}

	//Checks to see if adding something with zero quantity is successful
	public void testAddInventory6(){
		assertTrue(cm.addInventory(0, 0,0,0));
	}

	
	//Checks to see checkInventory is successful
	public void testCheckInventory(){
		assertTrue(cm.checkInventory().equals(i));
	}
	
	//Testing a normal making coffee scenario
	public void testMakeCoffee1(){
		cm.addInventory(40, 20, 30, 50);
		cm.addRecipe(r1);
		assertEquals(cm.makeCoffee(r1, 100), 50, .05);
	}
	
	//Testing if there are not enough ingredients
	public void testMakeCoffee2(){
		cm.addRecipe(r1);
		cm.makeCoffee(r1, 100);
		cm.makeCoffee(r1, 100);
		cm.makeCoffee(r1, 100);
		cm.makeCoffee(r1, 100);
		cm.makeCoffee(r1, 100);
		cm.makeCoffee(r1, 100);
		assertEquals(cm.makeCoffee(r1, 100), 100, .05);
	}
	
	//Testing if there are insufficient funds
	public void testMakeCoffee3(){
		cm.addRecipe(r1);
		cm.addInventory(40, 20, 30, 50);
		assertEquals(cm.makeCoffee(r1, 25), 25, .05);
	}

	//Testing if we pay the exact price
	public void testMakeCoffee4(){
		cm.addRecipe(r1);
		
		assertEquals(cm.makeCoffee(r1, 50), 0, .05);
	}
		
	public void testMakeCoffee5(){
		cm.addRecipe(r1);
		cm.makeCoffee(r1, 50);
		
		assertEquals(i.getChocolate(), 14, .05);
		assertEquals(i.getCoffee(), 9, .05);
		assertEquals(i.getMilk(), 14, .05);
		assertEquals(i.getSugar(), 14, .05);
	}
	
	//Checks to see if the getRecipeForName returns the correct object
	public void testGetRecipeForName(){
		cm.addRecipe(r1);
		assertEquals(cm.getRecipeForName("Coffee"), r1);
	}
	
	public void testGetRecipes(){
		cm.addRecipe(r1);
		Recipe[] r = cm.getRecipes();
		assertSame(r[3], r1);
	}
	
	public void tearDown(){
		r1 = null;
		i = null;
		cm = null;
	}
	
}